<?php echo $this->render('global/uploader.phtml'); ?>

<?php 
$this->headScript()->appendFile($this->baseUrl().'/public/js/ckeditor.js' ); 
echo $this->inlineScript()->setScript(' 
$(document).ready(function(){
	CKEDITOR.replaceAll( "textarea", {
			toolbar : [ [ "Source", "-", "Bold", "Italic", "Underline", "Strike","TextColor","-","Link","Image","Flash","Table","HorizontalRule","Smiley","SpecialChar","PageBreak" ] ],
			width: 600
		}
	); 

});
');
?>

<table>
	<tr>
		<td>
			<a class="button" href="<?php echo $this->baseUrl() ?>/cpproducts">
				<div style="background:url(<?php echo $this->baseUrl() ?>/public/images/left_16.png);" class="inb">Wróć do listy</div>
			</a>
		</td>
		<td>
			<a class="button" href="javascript:void(null)" onclick="$('#formitem').submit()">
				<div style="background:url(<?php echo $this->baseUrl() ?>/public/images/save_16.png);" class="inb">Zapisz</div>
			</a>
		</td>
	</tr>
</table>

<form id="formitem" action="<?php echo $this->baseUrl() ?>/cpproducts/item<?php echo isSet( $this->p_id ) ? '/id/' . $this->p_id : '' ?>" method="post">
<table cellspacing="0" cellpadding="6" class="tform">
	<tr>
		<td class="lb">Nazwa PL:</td>
		<td colspan="2" class="inpy">
			<?php if( isSet( $this->err_name_pl ) ) { ?>
				<input style="border:1px solid red;" type="text" name="name_pl" value="" />
				<div class="formerror"><?php echo $this->err_name_pl ?></div>
			<?php } else { ?>
				<input type="text" id="name_pl" name="name_pl" value="<?php echo $this->name_pl ?>" />
			<?php } ?>
		</td>
	</tr>
	<tr>
		<td class="lb">Nazwa EN:</td>
		<td colspan="2" class="inpy"><input type="text" name="name_en" value="<?php echo $this->name_en ?>" /></td>
	</tr>
	<tr>
		<td class="lb">Nazwa CS:</td>
		<td colspan="2" class="inpy"><input type="text" name="name_cs" value="<?php echo $this->name_cs ?>" /></td>
	</tr>

	<tr>
		<td class="lb">Opis PL:</td>
		<td colspan="2" class="inpy"><textarea class="textarea" name="description_pl"><?php echo $this->description_pl ?></textarea></td>
	</tr>
	<tr>
		<td class="lb">Opis EN:</td>
		<td colspan="2" class="inpy"><textarea class="textarea" name="description_en"><?php echo $this->description_en ?></textarea></td>
	</tr>
	<tr>
		<td class="lb">Opis CS:</td>
		<td colspan="2" class="inpy"><textarea class="textarea" name="description_cs"><?php echo $this->description_cs ?></textarea></td>
	</tr>
	<tr>
		<td class="lb">Zastosowanie PL:</td>
		<td colspan="2" class="inpy"><textarea class="textarea" name="application_pl"><?php echo $this->application_pl ?></textarea></td>
	</tr>
	<tr>
		<td class="lb">Zastosowanie EN:</td>
		<td colspan="2" class="inpy"><textarea class="textarea" name="application_en"><?php echo $this->application_en ?></textarea></td>
	</tr>
	<tr>
		<td class="lb">Zastosowanie CS:</td>
		<td colspan="2" class="inpy"><textarea class="textarea" id="application_cs" name="application_cs"><?php echo $this->application_cs ?></textarea></td>
	</tr>
	<tr>
		<td class="lb">Recenzja PL:</td>
		<td colspan="2" class="inpy"><textarea class="textarea" name="test_pl"><?php echo $this->test_pl ?></textarea></td>
	</tr>
	<tr>
		<td class="lb">Recenzja EN:</td>
		<td colspan="2" class="inpy"><textarea class="textarea" name="test_en"><?php echo $this->test_en ?></textarea></td>
	</tr>
	<tr>
		<td class="lb">Recenzja CS:</td>
		<td colspan="2" class="inpy"><textarea class="textarea" name="test_cs"><?php echo $this->test_cs ?></textarea></td>
	</tr>
	<tr>
		<td class="lb">Specyfikacja PL:</td>
		<td colspan="2" class="inpy"><textarea class="textarea" name="specification_pl"><?php echo $this->specification_pl ?></textarea></td>
	</tr>
	<tr>
		<td class="lb">Specyfikacja EN:</td>
		<td colspan="2" class="inpy"><textarea class="textarea" name="specification_en"><?php echo $this->specification_en ?></textarea></td>
	</tr>
	<tr>
		<td class="lb">Specyfikacja CS:</td>
		<td colspan="2" class="inpy"><textarea class="textarea" name="specification_cs"><?php echo $this->specification_cs ?></textarea></td>
	</tr>
	<tr>
		<td class="lb">Produkt nie będzie brany pod uwagę przy obliczaniu rozmiaru paczki:</td>
		<td colspan="2" class="inpy">
			<label><input <?php echo ( $this->no_size > 0 ) ? 'checked="checked"' : ''; ?> type="radio" name="no_size" value="1" /> Tak</label>
			<label><input <?php echo ( $this->no_size < 1 ) ? 'checked="checked"' : ''; ?> type="radio" name="no_size" value="0" /> Nie</label>
		</td>
	</tr>
	<tr>
		<td class="lb">Widoczny dla rangi 1:</td>
		<td colspan="2" class="inpy">
			<label><input <?php echo ( $this->r1 == 'yes' ) ? 'checked="checked"' : ''; ?> type="radio" name="r1" value="yes" /> Tak</label> <label><input <?php echo ( $this->r1 == 'no' ) ? 'checked="checked"' : ''; ?> type="radio" name="r1" value="no" /> Nie</label>
		</td>
	</tr>
	<tr>
		<td class="lb">Widoczny dla rangi 2:</td>
		<td colspan="2" class="inpy">
			<label><input <?php echo ( $this->r2 == 'yes' ) ? 'checked="checked"' : ''; ?> type="radio" name="r2" value="yes" /> Tak</label> <label><input <?php echo ( $this->r2 == 'no' ) ? 'checked="checked"' : ''; ?> type="radio" name="r2" value="no" /> Nie</label>
		</td>
	</tr>
	<tr>
		<td class="lb">Widoczny dla rangi 3:</td>
		<td colspan="2" class="inpy">
			<label><input <?php echo ( $this->r3 == 'yes' ) ? 'checked="checked"' : ''; ?> type="radio" name="r3" value="yes" /> Tak</label> <label><input <?php echo ( $this->r3 == 'no' ) ? 'checked="checked"' : ''; ?> type="radio" name="r3" value="no" /> Nie</label>
		</td>
	</tr>
	<tr>
		<td class="lb">Widoczny dla rangi 4:</td>
		<td colspan="2" class="inpy">
			<label><input <?php echo ( $this->r4 == 'yes' ) ? 'checked="checked"' : ''; ?> type="radio" name="r4" value="yes" /> Tak</label> <label><input <?php echo ( $this->r4 == 'no' ) ? 'checked="checked"' : ''; ?> type="radio" name="r4" value="no" /> Nie</label>
		</td>
	</tr>
	<tr>
		<td class="lb">Widoczny dla rangi VIP:</td>
		<td colspan="2" class="inpy">
			<label><input <?php echo ( $this->r5 == 'yes' ) ? 'checked="checked"' : ''; ?> type="radio" name="r5" value="yes" /> Tak</label> <label><input <?php echo ( $this->r5 == 'no' ) ? 'checked="checked"' : ''; ?> type="radio" name="r5" value="no" /> Nie</label>
		</td>
	</tr>
	<tr>
		<td class="lb">Kategorie:</td>
		<td colspan="2" class="inpy"><?php echo $this->Categories( $this->categoriesList, $this->categories ) ?></td>
	</tr>
	<tr>
		<td class="lb">Tagi:</td>
		<td colspan="2" class="inpy">
		<?php foreach( $this->tagList as $value ) { ?>
			<?php $sel = in_array( $value->t_id, $this->tags ) ? 'checked="checked"' : '' ?>
			<label class="tag"><input <?php echo $sel; ?> type="checkbox" name="tags[]" value="<?php echo $value->t_id ?>" /> <?php echo $value->name_pl ?></label>
		<?php } ?>
		</td>
	</tr>
	<tr>
		<td class="lb">Producent:</td>
		<td colspan="2" class="inpy">
			<select name="manufacturers_m_id">
			<?php foreach( $this->manufacturersList as $value ) { ?>
				<option <?php echo ( $this->manufacturers_m_id == $value['m_id'] ) ? 'selected="selected"' : ''; ?> value="<?php echo $value->m_id ?>"><?php echo $value->name_pl ?></option>
			<?php } ?>
			</select>
		</td>
	</tr>
	<tr>
		<td class="lb">Vat:</td>
		<td colspan="2" class="inpy">
			<select name="vat_v_id">
			<?php foreach( $this->vatList as $value ) { ?>
				<option <?php echo ( $this->vat_v_id == $value['v_id'] ) ? 'selected="selected"' : ''; ?> value="<?php echo $value->v_id ?>"><?php echo $value->rate ?> %</option>
			<?php } ?>
			</select>
		</td>
	</tr>
	<tr>
		<td class="lb">Wybierz galerię:</td>
		<td class="inpy" style="width:200px;">
			<select id="galeries_g_id" name="galeries_g_id">
			<?php foreach( $this->galleriesList as $value ) { ?>
				<option <?php echo ( $this->galeries_g_id == $value['g_id'] ) ? 'selected="selected"' : ''; ?> value="<?php echo $value->g_id ?>"><?php echo $value->name ?></option>
			<?php } ?>
			</select>
		</td>
		<td style="width:160px;"><a class="button" style="width:160px;" onclick="showUploader(true);" href="javascript:void(null)">Wczytaj zaznaczoną</a></td>
		<td><a class="button" style="width:120px;" onclick="showUploader();" href="javascript:void(null)">Dodaj galerię</a></td>
	</tr>
</table>
</form>
<div id="dialog" style="display:none;" title="Uploader">
<?php if( isSet( $this->p_id ) ) { ?>
<?php } else { ?>

<?php } ?>
<table cellspacing="0" cellpadding="6" class="tform">
	<tr>
		<td class="inpy" colspan="2">
			<div id="fcont">
				<ul id="sortable">
				<?php foreach( $this->listGallery as $value ) { ?>
				<li class="ui-state-default">
					<div <?php echo ( $value['main'] == 'yes' ) ? 'style="background:#FEFF6F;"' : '' ?> class="img">
						<a style="color:#000" onclick="return confirmDelete();" class="delete" href="<?php echo $this->baseUrl() ?>/cpgaleries/deleteitem/id/<?php echo $value['ph_id'] ?>/g_id/<?php echo $this->g_id ?>">Usuń</a>
						<?php if ( $value['main'] == 'no' ) { ?> 
							<a style="color:#000" class="glowne" href="<?php echo $this->baseUrl() ?>/cpgaleries/setgl/id/<?php echo $value['ph_id'] ?>/g_id/<?php echo $this->g_id ?>">Główne</a>
						<?php } ?>
						<img src="<?php echo $this->File( $value['iden'], 112 ) ?>" />
					</div>
					<input type="hidden" name="orders[]" value="<?php echo $value['ph_id'] ?>">
				</li>
				<?php } ?>
				</ul>
			</div>
		</td>
	</tr>
	<tr>
		<td class="lb">Dodaj zdjęcia:</td>
		<td class="inpy">
			<div style="clear:both;">
				<div class="fieldset flash" id="fsUploadProgress1">
					<span class="legend"></span>
				</div>
				<div style="padding-left: 5px;">
					<span id="spanButtonPlaceholder1"></span>
					<input id="btnCancel1" type="button" value="Anuluj" onclick="cancelQueue(upload1);" disabled="disabled" style="margin-left: 2px; height: 22px; font-size: 8pt;width:120px;" />
					<br />
				</div>
			</div>
		</td>
	</tr>	
</table>

</div>
<script type="text/javascript">
var callbackIn = function( resp ) {
	
	for( var i = 0, len = resp.length; i < len; i++ ) {

		if( resp[i].main == 'yes' ) {			
			var elemnew = '<li class="ui-state-default">' +
			'<div id="n' + resp[i].ph_id + '" style="background:#FEFF6F;" class="img">' +
					'<a style="color:#000;" onclick="return confirmDeleteHandler(this, ' + resp[i].ph_id + ');" class="delete" href="' + baseUrl + '/cpgaleries/deleteitem/id/' + resp[i].ph_id + '/g_id/' + galleryId + '">Usuń</a>' +
					'<img src="' + baseUrl + '/public/uploads/' + resp[i].iden.replace( ".jpg", "_112.jpg" ) + '" />' +
				'</div>' +
			'</li>';
		} else {
			var elemnew = '<li class="ui-state-default">' +
			'<div id="n' + resp[i].ph_id + '" class="img">' +
					'<a style="color:#000;" onclick="return confirmDeleteHandler(this, ' + resp[i].ph_id + ');" class="delete" href="' + baseUrl + '/cpgaleries/deleteitem/id/' + resp[i].ph_id + '/g_id/' + galleryId + '">Usuń</a>' +
					'<a style="color:#000;" onclick="return setGl(this, ' + resp[i].ph_id + ')" class="glowne" href="' + baseUrl + '/cpgaleries/setgl/id/' + resp[i].ph_id + '/g_id/' + galleryId + '">Główne</a>' +
					'<img src="' + baseUrl + '/public/uploads/'  + resp[i].iden.replace( ".jpg", "_112.jpg" ) + '" />' +
				'</div>' +
			'</li>';
		}
		
		var dvover = $( '#sortable' ).append( elemnew );

		$( "#n" + resp[i].ph_id ).hover(function(){
			$(this).find( "a" ).css({ opacity: 0, display : "block", cursor : "pointer" }).animate({
				opacity : 0.9
			});
		}, function(){
			$(this).find( "a" ).animate({
				opacity : 0
			});
		});
	}
};
</script>
<?php 

echo $this->inlineScript()->setScript('
	var showUploader;
	
	var galleryId = false;
	
	$(document).ready(function(){
		showUploader = function( load ) {
			$( "#sortable" ).empty();
		
			var load = load || false;

			if( load ) {
				galleryId = $( "#galeries_g_id" ).val();
				
				$.post(
					baseUrl + "/cpproducts/item/ajax/1/galleryid/" + galleryId,
					null,
					function( resp ) { callbackIn( resp ); },
					"json"
				);
			} else {
				galleryId = false;
			}
		
		
			$("button").button({
				 icons: {
	                primary: "ui-icon-gear"
	            }
			}).click(function(){
			
			});
		
			$(function() {
				$("#dialog").dialog({
					modal: true,
					width: "840px",
					height: "auto"
				});
			});
			
			$( "div.img" ).hover(function(){
				$(this).find( "a" ).css({ opacity: 0, display : "block", cursor : "pointer" }).animate({
					opacity : 0.9
				});
			}, function(){
				$(this).find( "a" ).animate({
					opacity : 0
				});
			});
			
			$("#sortable").sortable();
			
		}	
	});
'); ?>

<table>
	<tr>
		<td>
			<a class="button" href="<?php echo $this->baseUrl() ?>/cpproducts/list">
				<div style="background:url(<?php echo $this->baseUrl() ?>/public/images/left_16.png);" class="inb">Wróć do listy</div>
			</a>
		</td>
		<td>
			<a class="button" href="javascript:void(null)" onclick="$('#formitem').submit()">
				<div style="background:url(<?php echo $this->baseUrl() ?>/public/images/save_16.png);" class="inb">Zapisz</div>
			</a>
		</td>
	</tr>
</table>